package javaExample;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author admin
 *         实现2的100次方
 */
public class JavaTwoPower {
    public static void main(String[] args) {
        JavaTwoPower jtp = new JavaTwoPower();
        jtp.TwoPower();
        System.out.println(jtp.TwoPower().toString());
        jtp.ArrayTwo();

    }

    public List TwoPower() {
        final int COUNT = 100;
        LinkedList<Integer> result = new LinkedList<Integer>();
        result.add(1);
        for (int i = 0; i < COUNT; i++) {
            // 进位标志位
            int flag = 0;
            int size = result.size();
            for (int j = size - 1; j >= 0; j--) {
                int p = result.get(j) * 2 + flag;
                flag = p / 10;
                p %= 10;
                result.set(j, p);
            }
            // 最高位添加进位
            if (flag == 1) {
                result.addFirst(1);
            }
        }
        return result;
    }
    public List ArrayTwo(){
        ArrayList<Integer>  arraylist = new ArrayList<Integer>();
        final int count = 100;
        int flag = 0;
        int num = 1;
        int yu = 0;
        arraylist.add(1);
        while (num<101) {
            flag = 0;
            for (int i = 0; i < arraylist.size(); i++) {
                int ruslt = arraylist.get(i) * 2 + flag;
                flag = ruslt / 10;
                yu = ruslt % 10;
                arraylist.set(i,yu);
            }
            if (flag == 1) {
                arraylist.add(1);
            }
            num++;
        }
        for(int j = arraylist.size()-1;j>=0;j--){
            System.out.print(arraylist.get(j));
        }
        return arraylist;
    }
}
